//
//  DKTabBarController.swift
//  Sina
//
//  Created by 赵柏清 on 16/7/29.
//  Copyright © 2016年 DarkZhao. All rights reserved.
//

import UIKit

class DKTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        addChildViewController()
        
        
        // 自定义tabBar
        let DKtab = DKTabBar()
        
        DKtab.tintColor = UIColor.orangeColor()
        
        setValue(DKtab, forKey: "tabBar")
        
    }
    
    func addChildViewController() {
        addChildViewController(DKHomeViewController(), imageName: "tabbar_home", titleString: "首页")
        addChildViewController(DKMessageViewController(), imageName: "tabbar_message_center", titleString: "消息")
        addChildViewController(DKFindViewController(), imageName: "tabbar_discover", titleString: "发现")
        addChildViewController(DKSettingViewController(), imageName: "tabbar_profile", titleString: "我")
    }
    
    
    // MARK: 重载addChildViewController方法
    func addChildViewController(childController: UIViewController,imageName: String,titleString: String) {
        
        // 设置子控制器的tabBar标题
        childController.tabBarItem.title = titleString
        
        // 设置子控制器tabBar的图片
        // 普通状态
        childController.tabBarItem.image = UIImage(named: imageName)
        // 选中状态
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_highlighted")
        // 设置渲染的颜色
        tabBar.tintColor = UIColor.orangeColor()
        // 把控制器用navigation包装
        let nav = UINavigationController(rootViewController: childController)
        // 设置导航栏的标题
        childController.navigationItem.title = titleString
        // 添加子控制器
        addChildViewController(nav)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
